package com.heima.common.exception;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionCatch {


    @ExceptionHandler(value = Exception.class)
    public ResponseResult execption(Exception ex) {
        log.error("出现异常了，我知道，但我不说~", ex.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "服务器繁忙！");
    }

    @ExceptionHandler(value = CustomException.class)
    public ResponseResult custException(Exception ex) {
        CustomException customException = (CustomException) ex;
        log.error("出现异常了，我知道，但我不说~", ex.getMessage());
        return ResponseResult.errorResult(customException.getAppHttpCodeEnum());
    }
}
